<?php
/**
 * @file cooperationdefine.php
 * @author CaoQiCheng
 * @date 2016年4月26日 下午17:16:11
 * @brief 
 */

namespace haibao\cms\data\artist;

use haibao\cms\business\control\PublicController;
class ArtistInsideSecrecy extends \haibao\cms\data\BaseMysql{

    public function __construct(){
        parent::__construct('\haibao\cms\model\data\artist\artistinsidesecrecy');
    }
    
	/**
	 * 添加保密信息
	 */
	public function addArtistInside($artistInsideModel){
			if($artistInsideModel->Id){
				parent::updateById($artistInsideModel->Id, $artistInsideModel);
				$this->addArtistContacts($artistInsideModel->Id, $artistInsideModel->ArtistContacts);
				$this->addArtistSchedule($artistInsideModel->Id, $artistInsideModel->ArtistCooperationSchedule);
			}else {
				parent::add($artistInsideModel);
				$this->addArtistContacts($artistInsideModel->Id, $artistInsideModel->ArtistContacts);
				$this->addArtistSchedule($artistInsideModel->Id, $artistInsideModel->ArtistCooperationSchedule);
			}
	}
	
	/**
	 * 添加联系人
	 */
	public function addArtistContacts($artistId,$artistContactsModel){
		$this->query('delete from `ArtistContacts` where ArtistInsideId = %s', array(
				$artistId
		));
		if(!$artistId){
			return false;
		}
		if($artistContactsModel){
			$sql = 'insert into ArtistContacts(ArtistInsideId,ContactType,ContactName,CellPhone,WeChat) values ';
			$arrSql = $arrValues = array();
			foreach($artistContactsModel as $key=>$val){
				array_push($arrSql, '(%s,%s,%s,%s,%s)');
				array_push($arrValues, $artistId);
				array_push($arrValues, $val->ContactType);
				array_push($arrValues, $val->ContactName);
				array_push($arrValues, $val->CellPhone);
				array_push($arrValues, $val->WeChat);
			}
			if($arrSql && $arrValues){
				$sql .= implode(',', $arrSql);
				$this->query($sql, $arrValues);
			}
		}
		
	}
	
	/**
	 * 添加合作进度
	 */
	public function addArtistSchedule($artistId,$artistScheduleModel){
		$this->query('delete from `ArtistCooperationSchedule` where ArtistInsideId = %s', array(
				$artistId
		));
		if(!$artistId){
			return false;
		}
		if($artistScheduleModel){
			$sql = 'insert into ArtistCooperationSchedule(ArtistInsideId,ScheduleType,ScheduleDate,ScheduleDesc) values ';
			$arrSql = $arrValues = array();
			foreach($artistScheduleModel as $key=>$val){
				array_push($arrSql, '(%s,%s,%s,%s)');
				array_push($arrValues, $artistId);
				array_push($arrValues, $val->ScheduleType);
				array_push($arrValues, $val->ScheduleDate);
				array_push($arrValues, $val->ScheduleDesc);
			}
			if($arrSql && $arrValues){
				$sql .= implode(',', $arrSql);
				$this->query($sql, $arrValues);
			}
		}
		
	}
	
}